import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/view/index'
import Info from '@/components/view/info'
import shop from '@/components/view/shop.vue'
import mine from '@/components/view/mine.vue'
import classify from '@/components/view/classify.vue'
import classinfo from '@/components/view/classinfo.vue'
import login from '@/components/view/login.vue'
import regisrer from '@/components/view/regisrer.vue'
Vue.use(Router)

  const router = new Router({
  routes: [
    {
      path: '/',
      name: 'index',
      component: HelloWorld,
      meta:{
        isLogin:false
      }
    },
    {
      path: '/info/:id',
      name: 'info',
      component: Info
    },
    {
      path: '/shop',
      name: 'shop',
      component: shop,
      meta:{
        isLogin:false
      }
    },
    {
      path: '/classify',
      name: 'classify',
      component: classify,
      meta:{
        isLogin:false
      }
    },
    {
      path: '/mine',
      name: 'mine',
      component: mine,
      meta:{
        isLogin:true
      }
    },
    {
      path: '/classinfo/:id',
      name: 'classinfo',
      component: classinfo
    },
    {
      path: '/login',
      name: 'login',
      component: login
    },
    {
      path: '/regisrer',
      name: 'regisrer',
      component:regisrer
    }
    
  ]
 
})
router.beforeEach((to, from, next) => {
 if(to.meta.isLogin){
   next({
     path:'/login',
     query:{redirect:to.fullPath}
   })
 }else{
   next()
 }

})
export default router